﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;

namespace MISAPP.Classify.DataAccess
{
    public class DA_CFG001 : DA_Matrix
    {
        protected static object obj = null;

        public DA_CFG001()
        {
            tableName = "CFG001";
            //System.Diagnostics.Trace 

        }

        public override string[] GetDistinctField()
        {
            return new string[]{"YYYYMM","會計科目"
                            ,"產品名稱","專案名稱"
                            ,"客層"};
        }

        public static DA_CFG001 GetInstance()
        {
            if (obj == null)
            {
                obj = InstanceHelper.CreateInstance("DA_CFG001");
            }
            return obj as DA_CFG001;
        }

        public DataTable GetGroupBy()
        {
            DA_MISParameter para = new DA_MISParameter();
            DataTable dt = para.GetParameter("CIB", "GROUPBY");
            return dt;
            //return base.GetGroupBy("CIB", tableName);
        }

        public DataTable GetProjectInfo(string p_id)
        {
            string sql = @"SELECT DISTINCT A.專案代碼,A.專案名稱 FROM CFG001 AS A 
WHERE A.專案代碼 LIKE @p_id                            
ORDER BY  A.專案代碼,A.專案名稱";
            p_id = string.Format("{0}%", p_id.ToUpper().Trim());
            FillTableSchema("CFG001");
            FillFieldList(new string[] { p_id}
                , new string[] { "@p_id" }
                , "專案代碼");
            AddParameter(sql);
            return getData();
        }

        //~DA_CFG001()
        //{
        //    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"D:\DA_CFG001.txt"))
        //    {
        //        // Add some text to the file.
        //        sw.Write("This is the ");
        //        sw.WriteLine("header for the file.");
        //        sw.WriteLine("-------------------");
        //        // Arbitrary objects can also be written to the file.
        //        sw.Write("The date is: ");
        //        sw.WriteLine(DateTime.Now);
        //        sw.Close();
        //    }

        //}
    }
}
